// store/index.js

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    items: [
      { id: 1, name: '商品1', price: 100 },
      { id: 2, name: '商品2', price: 200 },
      { id: 3, name: '商品3', price: 300 }
    ],
    cart: []
  },
  mutations: {
    addToCart(state, item) {
      state.cart.push(item)
    },
    removeFromCart(state, index) {
      state.cart.splice(index, 1)
    }
  },
  getters: {
    totalPrice(state) {
      return state.cart.reduce((total, item) => total + item.price, 0)
    }
  }
})
